﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BaseData_CompanyArea : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind_WL();
            Bind_Province();
        }
    }
    //绑定物流公司
    private void Bind_WL()
    {
        DropDownList1.DataSource = new BLL.TRANER().GetAllList(true);
        DropDownList1.DataTextField = "TRANER_NAME";
        DropDownList1.DataValueField = "TRANER_CODE";
        DropDownList1.DataBind();
    }
    //绑定省
    private void Bind_Province()
    {
        DropDownList2.DataSource = new BLL.Province().GetAllList();
        DropDownList2.DataTextField = "ProName";
        DropDownList2.DataValueField = "ProID";
        DropDownList2.DataBind();
    }
    //绑定市
    private void Bind_City(string Proid)
    {
        if (Proid.Length > 1)
        {
            DropDownList3.DataSource = new BLL.City().GetAllList(Proid);
            DropDownList3.DataTextField = "CityName";
            DropDownList3.DataValueField = "CityID";
            DropDownList3.DataBind();
        }
    }
    //初始化收费标准信息
    private void Init_Standard()
    {
        if (DropDownList1.SelectedIndex > 0 && DropDownList3.SelectedIndex > 0)
        {
            Model.TRANERCOST trancost = new Model.TRANERCOST();
            trancost = new BLL.TRANERCOST().GetModel(DropDownList1.SelectedValue, DropDownList3.SelectedValue);
            if (trancost != null)
            {
                Tbx_Fweight.Text = trancost.TC_FWEIGHT.ToString("f");
                Tbx_Fprice.Text = trancost.TC_FWEIGHTPRICE.ToString("f");
                Tbx_Eweight.Text = trancost.TC_NWEIGHT.ToString("f");
                Tbx_Eprice.Text = trancost.TC_NWEIGHTPRICE.ToString("f");
            }
        }

    }
    //添加修改
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex < 1)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('请选择物流公司!')", true);
            return;
        }
        if (DropDownList3.SelectedIndex < 1)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('请选择城市!')", true);
            return;
        }
        if (Tbx_Fweight.Text.Length < 1)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('请输入首重!')", true);
            return;
        }
        if (Tbx_Fprice.Text.Length < 1)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('请输入首重价格!')", true);
            return;
        }
        if (Tbx_Eweight.Text.Length < 1)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('请输入续重!')", true);
            return;
        }
        if (Tbx_Eprice.Text.Length < 1)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('请输入续重价格!')", true);
            return;
        }
        if(new BLL.TRANERCOST().TranCost_Insert(DropDownList1.SelectedValue,DropDownList3.SelectedValue,decimal.Parse(Tbx_Fweight.Text.Trim()),decimal.Parse(Tbx_Fprice.Text.Trim()),decimal.Parse(Tbx_Eweight.Text.Trim()),decimal.Parse(Tbx_Eprice.Text.Trim())))
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('保存成功!')", true);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('保存失败!')", true);
        }
    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        if(DropDownList2.SelectedIndex>1)
        {
            Bind_City(DropDownList2.SelectedValue);
        }       
    }
    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {
        Init_Standard();
    }
}
